package top.heue.text.util;

import java.util.ArrayList;
import java.util.List;

import opensource.jpinyin.PinyinHelper;
import top.heue.text.bean.ContentListBean;

import static opensource.jpinyin.PinyinFormat.WITH_TONE_MARK;

public class ListUtil {
    public  static List<ContentListBean> listFormat(String string, int width) {
        List<ContentListBean> list = new ArrayList<>();
        String[] strings = string.split("");
        String p;
        ContentListBean bean;int size;
        for (String str : strings) {
            if (str.equals("\n")) {
                size = list.size();
                while(size > width) size = size - width;
                size = width - size;
                bean = new ContentListBean("", "");
                for (int i = 0; i < size; i++) {
                    list.add(bean);
                }
            } else {
                p = changeToMarkPinYin(str);
                bean = new ContentListBean(p, str);
                list.add(bean);
            }
        }
        return list;
    }

    public static String changeToMarkPinYin(String pinYinStr) {
        String tempStr = null;
        try {
            tempStr =  PinyinHelper.convertToPinyinString(pinYinStr,  " ", WITH_TONE_MARK);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tempStr;
    }
}
